package com.ly.controller;

import cn.hutool.core.util.StrUtil;
import com.ly.handler.BusinessException;
import com.ly.response.Result;
import com.ly.response.ResultCode;
import com.ly.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin  //解决跨域
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 在用户注册之前检测用户存在
     */
    @GetMapping("/ckusr")
    public Result ckusr(String name) {
        if(StrUtil.isEmpty(name)){
            throw  new BusinessException(ResultCode.PARAM_IS_BLANK.getCode(),"必须要传递参数name");
        }
        boolean flag = userService.checkUser(name);
        if (flag) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
}
